<% @title = "#{@form.name}" %>
<% locale_was = I18n.locale; I18n.locale = @lang %>
<div class="sms_guide">
  <div class="header"><%= t("sms_forms.guide.header") %></div>
  <h1 class="printable"><%= @title %></h1>
  <div class="controls">
    <form>
      <input type="hidden" name="sms_guide" value="1">
      Language: 
      <select name="lang" onchange="this.form.submit();">
        <%= I18n.available_locales.collect{|l| content_tag(:option, language_name(l), 
            {:value => l}.merge(@lang.to_s == l.to_s ? {:selected => "selected"} : {}))}.join.html_safe %>
      </select>
    </form>
    
    <%= link_to_if_auth("SMS Test Console", new_sms_test_path, "sms_tests#create") %>
  </div>
  <table>
    <tr>
      <td colspan="2" class="step1">
        <strong><%= t("common.step") %> 1:</strong> <%= t("sms_forms.guide.step1") %>
      </td>
      <td class="answers"></td>
    </tr>
    <tr>
      <td class="rank"></td>
      <td class="pointer">
        <em><%= t("sms_forms.guide.unique_code") %> </em>
      </td>
      <td class="answers">
        <%= answer_space(@form.current_version.code) %>
      </td>
    </tr>
    
    <%# loop over each question %>
    <% @form.smsable_questionings.each do |qing| %>
      <tr>
        <td class="rank"><%= qing.rank %>.</td>
        <td class="question"><%= qing.question.send("name_#{@lang}") %></td>
        <td class="answers">
          <%= answer_space(" #{qing.rank}.") %>
        </td>
      </tr>
      
      <%# options area, for select_* questions %>
      <% if qing.question.type.has_options? %>
        <tr>
          <td class="rank"></td>
          <td class="options">
            <% qing.question.options.each_with_index do |opt, idx| %>
              <span><%= index_to_letter(idx + 1) %>) <%= opt.send("name_#{@lang}") %></span>
            <% end %>
          </td>
          <td class="answers"></td>
        </tr>
      <% end %>
      
      <%# pointer/answer row, depends on question type %>
      <tr>
        <td class="rank"></td>
        <td class="pointer">
          <em>
            <%= t("sms_forms.guide.pointers.#{qing.question.type.name}") %>
            <%= sms_example_for_question(qing) %>
          </em>
        </td>
        <td class="answers">
          <%= answer_space_for_question(qing) %>
        </td>
      </tr>
    <% end %>
    
    <%# final instructions %>
    <tr>
      <td colspan="3" class="step2">
        <strong><%= t("common.step") %> 2:</strong> <%= t("sms_forms.guide.step2") %>
        <ol>
          <% t("sms_forms.guide.step2_substeps").each do |ss| %>
            <li><%= ss.gsub("%{submit_number}", submit_number).html_safe %></li>
          <% end %>
        </ol>
        <%= t("common.thank_you_with_exclamation") %>
      </td>
      <td></td>
    </tr>
    
  </table>
</div>
<% I18n.locale = locale_was %>